package com.sxu.greedy.day4;

import java.util.Arrays;

/**
 * 用最少数量的箭引爆气球
 */
public class Test23 {
    public int findMinArrowShots(int[][] points) {
        // 按照左端点排序
        Arrays.sort(points,(v1,v2)->{
            return v1[0] > v2[0] ? 1 : -1;
        });

        // 求互相重叠的区间的个数
        int right = points[0][1];
        int ret = 1;
        for(int i = 1;i<points.length;i++){
            int a = points[i][0];
            int b = points[i][1];
            if(a <= right){
                right = Math.min(b,right);
            } else {
                ret++;
                right = b;
            }
        }
        return ret;
    }
}
